package daily.kou2022_0227;

import java.util.Stack;

public class MyQueue {
    //232. 用栈实现队列
    //实际存储元素的栈
    private Stack<Integer> s1=new Stack<>();
    //辅助栈
    private Stack<Integer> s2=new Stack<>();

    //构造方法
    public MyQueue() {

    }

    public void push(int x) {
        if (s1.isEmpty()){
            s1.push(x);
        }else {
            while (!s1.isEmpty()){
                s2.push(s1.pop());
            }
            s1.push(x);
            while (!s2.isEmpty()){
                s1.push(s2.pop());
            }

        }


    }

    public int pop() {
        return s1.pop();

    }

    public int peek() {
        return s1.peek();

    }

    public boolean empty() {
        return s1.isEmpty();

    }
}
